package eworldpacs.ui;

import leadtools.dicom.DicomElement;
import leadtools.dicom.DicomTag;
import leadtools.dicom.DicomTagTable;

public class DicomDemoUtils {

   public static short GetGroup(long tag)
    {
       return ((short)(tag >> 16));
    }

    public static short GetElement(long tag)
    {
       return ((short)(tag & 0xFFFF));
    }
   
   public static String ElementToString(long tagValue)
    {
       String temp = String.format("%04X:%04X", GetGroup(tagValue), GetElement(tagValue));
       return temp;
    }
   
   public static String ElementNameToString(DicomElement element)
    {
       String name = "";
       if (element != null)
       {
          DicomTag tag = DicomTagTable.getInstance().find((int)element.getTag());
          if (tag != null)
             name = tag.getName();

       }
       return name;
    }
   
   public static String ElementToString(DicomElement element)
    {
       String ret = "";
       if (element != null)
       {
          String name = "";
          DicomTag tag = DicomTagTable.getInstance().find((int)element.getTag());
          if (tag != null)
          {
             name = tag.getName();
          }
          else
             name = "Item";

          ret = ElementToString(element.getTag()) + " - " + name;
       }

       return ret;
    }
   
   public static String ConvertByteArrayToString(byte[] byteArray)
    {
       //return (new UnicodeEncoding()).GetString(byteArray);
       //return System.Text.Encoding.Unicode.GetString(byteArray, 0, byteArray.Length);

       if (byteArray == null)
          return "";

       String s = "";
       for (byte b : byteArray)
       {
          s = s + String.format("%2X", b) + " ";
       }
       return s;
    }
}
